﻿#region FileHeader
/*
 * Author      : Veda Prakash Girmaji Associate Consultant
 *             : Rajeswari Mohandas Associate Consultant
 * Date        : 10-19-2010
 * Description : Class contains the Windows Powershell commandlet information.
 * Version     : 1.0
*/
#endregion

using System;
using System.IO;
using System.Text;
using System.Xml.Serialization;

namespace PSExplorer
{
    [Serializable]
    public class Cmdlet
    {
        private string name;
        private Examples examples;
        private string description;
        private string synopsis;
        private string syntax;

        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        public Examples Examples
        {
            get { return examples; }
            set { examples = value; }
        }

        public string Description
        {
            get { return description; }
            set { description = value; }
        }

        public string Synopsis
        {
            get { return synopsis; }
            set { synopsis = value; }
        }

        public string Syntax
        {
            get { return syntax; }
            set { syntax = value; }
        }

        public Cmdlet()
        {
            this.Name = string.Empty;
            this.Description = string.Empty;
            this.Synopsis = string.Empty;
            this.Syntax = string.Empty;

        }

        public string ToXml()
        {
            string xmlBuffer = string.Empty;
            try
            {
                XmlSerializer xmlFormat = new XmlSerializer(typeof(Cmdlet));
                using (Stream memoryStream = new MemoryStream())
                {
                    xmlFormat.Serialize(memoryStream, this);

                    byte[] buffer = new byte[memoryStream.Length];
                    memoryStream.Seek(0, SeekOrigin.Begin);
                    memoryStream.Read(buffer, 0, (int)memoryStream.Length);

                    ASCIIEncoding encoder = new ASCIIEncoding();
                    xmlBuffer = encoder.GetString(buffer);
                }
                return xmlBuffer;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}